Skip to content

timers: introduce timers/promises#33950

Closed
jasnell wants to merge 3 commits intonodejs:masterfrom
jasnell:timers-promises
Closed

timers: introduce timers/promises#33950
jasnell wants to merge 3 commits intonodejs:masterfrom
jasnell:timers-promises

Conversation

@jasnell
Copy link
Member

@jasnell jasnell commented Jun 18, 2020

Move the promisified timers implementations into a new experimental
sub-module to avoid the need to promisify. The promisified versions
now return the timers/promises versions.

Also adds ref option to the promisified versions

const {
  setTimeout,
  setImmediate
} = require('timers/promises');

setTimeout(10, null, { ref: false })
  .then(console.log);

setImmediate(null, { ref: false })
  .then(console.log);

// The promisify versions of the original timers return the same functions...
const timers = require('timers');
const { promisify } = require('util');
const assert = require('assert');

assert.strictEqual(promisify(timers.setTimeout), setTimeout);
assert.strictEqual(promisify(timers.setImmediate), setImmediate);

Needs the additional fixes implemented in #33949 ... this one is blocked on that one landing.

Signed-off-by: James M Snell jasnell@gmail.com

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Issues and PRs related to build files or the CI. semver-major PRs that contain breaking changes and should be released in the next major version. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.

Projects

None yet

Development

Successfully merging this pull request may close these issues.